﻿using System.Data.Entity;
using System.Windows;
using AppConfigSettings;
using ButsaForecast.al;
using ButsaLib;
using CustomConfigurationSettings;
using Microsoft.Practices.ServiceLocation;
using Ninject;
using Ninject.Modules;
using NinjectAdapter;

namespace ButsaForecast
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App
	{
		public IKernel Kernel;
		protected override void OnStartup(StartupEventArgs e)
		{
			base.OnStartup(e);

			Kernel = new StandardKernel(new ConfigurationModule());
			CustomConfigurationManager.Instance = Kernel.Get<IConfigurationManager>();
			var locator = new NinjectServiceLocator(Kernel);
			ServiceLocator.SetLocatorProvider(() => locator);
			
			//отключаем инициализатор базы данных
			Database.DefaultConnectionFactory = new ButsaConnectionFactory();
			//Database.SetInitializer<ButsaDbContext>(new DropCreateDatabaseAlways<ButsaDbContext>());
			Database.SetInitializer<ButsaDbContext>(null);
		}
	}

	internal class ConfigurationModule: NinjectModule
	{
		/// <summary>
		/// Loads the module into the kernel.
		/// </summary>
		public override void Load()
		{
			Bind<IConfigurationManager>().To<AppConfigManager>();
			Bind<ITeamEstimation>().To<TeamEstimationB>();
		}
	}
}
